<?php

namespace Home\Controller;
use Think\Controller;

/**
 *  个人信息
 *  @author zangyilei
 */

class AccountController extends HomeBaseController {

    /**
     *  账户修改
     */
    public function update(){
        
        $strEmail       = I('email');
        $Users          = D('Users');

        $Users->uid                         = $this->iUserId;
        $strEmail && $Users->email          = $strEmail;
//         $_FILES['photo'] && $User->photo    = $this->uploadfile('photo','Account',2*1024*1020);
        $res                                = $Users->save();

        if($res){
            $this->success('保存成功',1);
        }else {
            $this->error('保存失败');
        }
    }
    
    /**
     *  账户详情
     */
    public function detail(){
       
        
        $userInfo = M("Users")
            ->field("users.uid,
                    users.userName,
                    users.phoneNumber,
                    users.email,
                    users.photo,
                    users.create_time
                   ")
            ->where(array('users.uid'=>$this->iUserId))
            ->find();
        
        $userInfo['photo'] && $userInfo['photo'] = C('SITE_URL').$userInfo['photo'];
        if (empty($userInfo)){
            $this->error('无法查到该用户信息');
        }
        
        $this->returnList($userInfo,1);
    }

    /**
     *  修改密码
     *
     */
 /*    Public function changePwd(){
        $strPhone          = I('phone');
        $strPassword       = I('password');
        $strNewpassword    = I('newpassword');
        $strRepassword     = I('repassword');
        $User              = D('User');
    
        $rules = array(
            array('password', 'require','原密码不能为空', 1),
            array('newpassword', 'require','新密码不能为空', 1),
            array('newpassword', '/^[\S]{6,12}$/', '密码长度要求6-12位，不限制类型', 1),
            array('repassword', 'require','确认密码不能为空', 1),
            array('repassword','newpassword','两次密码输入不一致',0,'confirm')
        );
         
        if(!$User->validate($rules)->create()) {
            $this->error($User->getError());
        }
         
        $password = M("User")->where(array('user_id'=>$this->iUserId))->getField('password');
        if ($password != md5($strPassword)){
            $this->error('原密码不正确');
        }
         
        $User->user_id       = $this->iUserId;
        $User->password      = md5($strNewpassword);
        $res                 = $User->save();
         
        if($res){
            $this->success('修改成功',1);
        }else {
            $this->success('修改失败');
        }
     }*/
    
}